package com.ferry.wallpaper.utils.cg;

import java.awt.*;
import java.util.Locale;

public class FontUtils {

    /**
     * 获取系统可获取的字体名称
     * @return
     */


    public static String[] getAvailableFontFamilyNames() {
        GraphicsEnvironment environment = GraphicsEnvironment.getLocalGraphicsEnvironment();
        return environment.getAvailableFontFamilyNames();
    }

    /**
     * 获取合适的字体
     * @param FontFamilyName
     * @return
     */
    public static String ensureFontFamilyName(String FontFamilyName) {
        String[] availableFontFamilyNames = getAvailableFontFamilyNames();
        for (String availableFontFamilyName : availableFontFamilyNames) {
            if (FontFamilyName.equals(availableFontFamilyName)) {
                return FontFamilyName;
            }
        }
        return getDefault();
    }

    public static String getDefault() {
        String property = System.getProperty("os.name").toLowerCase(Locale.ROOT);
        if (property.contains("windows")) {
            return "文泉驿正黑";
        } else if (property.contains("linux")) {
            return "微软雅黑";
        } else {
            return "宋体";
        }
    }
}